#pragma once
/*
 * Copyright © 2008 University of Houston
 * All rights reserved
 */

#include <stdio.h>
#include <iostream>
#include <vector>
#include "algorithm.h"
#include "filter.h"
#include "resultsfilter.h"
#include "session.h"
#include "util.h"

using namespace std;

typedef vector<sessionAnalyzer*>		analyzer_list;

class resultsAnalyzer
{
public:
	/*
	 * Constructor.  Provides all of the parameters for computation.
	 * Note that this copies the contents of the provided results lists
	 * into internal buffers.
	 * @param 	resultsFilters		Vector of result-filter pairs.
	 * @param 	normal				Vector of normal results.
	 * @param 	longChains			Vector of long-chain results.
	 * @param 	shortChains			Vector of short-chain results.
	 */
	resultsAnalyzer(const vector <resFilterPair>	*resultsFilters,
					const vector<analyzerResultList> *normal=NULL,
					const vector<analyzerResultList> *longChains=NULL,
					const vector<analyzerResultList> *shortChains=NULL);
	// ~resultsAnalyzer();
	
	/*
	 * Returns the composite results after all of the results filtering.
	 * This is essentially a whole bunch of lines/points for plotting by the
	 * gnuplotter utility.
	 * @return 	vector<analyzerResultList>
	 * A listing of points to plot.	
	 */
	vector<analyzerResultList>*	getCompositeResults();
	vector<analyzerResultList>*	getExtra();
private:
	void doAnalysis();
	vector<analyzerResultList> doIndividualFilter(resultsFilter* f);
	void doInvidualFilterOnSet(resultsFilter* f, vector<analyzerResultList> *r);
	
	
	vector<analyzerResultList> 	rNormal;
	vector<analyzerResultList> 	rLong;
	vector<analyzerResultList> 	rShort;
	vector<resFilterPair>		resFilters;
	
	vector<analyzerResultList>	rComposite;
	vector<analyzerResultList>	rExtra;
};

class sessionAnalyzer
{
public:
    sessionAnalyzer() {};
    
	virtual ~sessionAnalyzer() {};

	/*
	 * Specifies the session, filter and algorithm for the analyzer to use. 
	 * Currently only one filter and algorithm can be seleted.
	 * @param sess The session to analyze
	 * @param filter The filter to use
	 * @param alg The selected algorithm
	 * @param sessID The session ID number
	 * @param logfile The name of the log
	 */
    virtual void initialize(session* sess, filter* filter, 
			algorithm* alg);
	
	/*
	 * Iterates through each packet in the given session and passes it to
	 * the filter.
	 * @param same as above
	 * @param sessID the session id number
	 * @param logfile The logfile name
	 */
	void simulate(session *sess, filter* filter, algorithm* alg, int sessID,
			string logfile);

	/*
	 * Passes the latest packet in our session to the filter, and if the 
	 * filter approves,it is passed to our algorithm
	 */
    void update();

	/*
	 * Returns an anlyzer object of the desired type as specified by
	 * analyzerID.
	 * @param analyzerID The analyzer subclass to return
	 */
	static sessionAnalyzer* 	getAnalyzer(int analyzerID);

	/*
	 * @return the list of results from our algorithm's analysis.
	 */
	analyzerResultList* getResultList();


	/*
	 * Loads all of the sessions in a given file into the specified vector.
	 * @param logfile 		Name of the log file
	 * @param v				Pointer to a vector to store the resultsLists
	 * @param sessPerLog	Pointer to a vector to store the # of sessions
	 *						per log.
	 * @param filterID		Filter ID number
	 * @param algID			Algorithm ID number
	 * @return 				No return value.
	 */
	static void loadFile(string logfile,
						vector<analyzerResultList>* v,
						int filterID=0,
						int algID=0);
						
	static bool recreate (vector<string> *logs, 
									vector<analyzerResultList> *v,
									int filterID,
									int algID);
									


protected:
    session 		*ourSession;
	filter 			*ourFilter;
	algorithm 		*ourAlg;
};

